package com.um.jdy.app.charge.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.charge.entity.vo.OrderItemVO;
import com.um.jdy.app.charge.entity.vo.OrderDetailVO;
import com.um.jdy.app.charge.manager.EBOrderManager;
import com.um.jdy.app.charge.manager.OrderManager;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/api/v1/order")
@SaCheckLogin
@Validated
@Api(tags = "充电订单-公共")
public class OrderController {

    @Autowired
    EBOrderManager ebOrderManager;

    @Autowired
    OrderManager orderManager;

    @ApiOperation("查询订单列表")
    @GetMapping("orders/page")
    public Response<Page<OrderItemVO>> getOrderPage(@ApiParam(value = "页码") @NotNull Integer page_no,
                                                    @ApiParam(value = "数据量") @NotNull Integer page_size,
                                                    @ApiParam(value = "订单状态") String order_status) {
        return Response.success(orderManager.getOrderPage(page_no,page_size,order_status));
    }

    @ApiOperation("查询订单详情")
    @GetMapping("orders/{id_or_no}")
    public Response<OrderDetailVO> getOrderInfo(@ApiParam("订单id") @PathVariable @NotBlank String id_or_no) {
        return Response.success(orderManager.getOrderInfo(id_or_no));
    }

    @ApiOperation("查询未完成订单")
    @GetMapping("charging/orders")
    public Response<List<OrderItemVO>> getChargingOrder() {
        return Response.success(orderManager.getChargingOrders());
    }
}
